package com.baosight.sczx.zm.cg.service;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.zm.cg.domain.ZMCGContactReceive;

/**
 * 业务联系单
 * <p>Title: ServiceZMCF25.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-7-6 上午07:44:02  严洪浩  Create
 *</pre>
 */
public class ServiceZMCG20 extends ServiceEPBase {

	/**
	 * 初始化方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCF25</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-8上午01:09:11 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(Department.getInstance().getConstructionUnit(false));//部门
		return outInfo;
	}

	/**
	 * 查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCF25</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-8上午01:09:01 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		if(inInfo.getBlock(EiConstant.queryBlock) == null){
			StaticTools.setQueryParameters(inInfo, "fdEndDate", StaticTools.getDate() + " 23:59:59", true);
		}
		else {
			String endTime = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdEndDate");
			if(null != endTime && !"".equals(endTime)) {
				if(endTime.length() <= 10) {
					StaticTools.setQueryParameters(inInfo, "fdEndDate", endTime + " 23:59:59", true);
				}
			}
		}

		String fdReceiveId = UserSession.getInSessionProperty("orgCode").toString();//发送部门
		StaticTools.setQueryParameters(inInfo, "fdReceiveId", fdReceiveId, true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdMiningId", UserSession.getInSessionProperty("miningCode"), true);
		EiInfo outInfo = super.query(inInfo, "ZMCGContactReceive.query", new ZMCGContactReceive());
		outInfo.addBlock(Department.getInstance().getConstructionUnit(false));//部门
		outInfo.addBlock(Department.getInstance().getMiningDepts("cmes.cp.department", "orgCode", "orgName", false,UserSession.getInSessionProperty("miningCode").toString()));
		outInfo.set("fdMiningId", UserSession.getInSessionProperty("miningCode"));//矿ID的默认值
		return outInfo;
	}
	
	/**
	 * 反馈
	 * <p>Function: feedback</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-8上午02:02:19 严洪浩
	 * </p>
	 *
	 */
	public EiInfo feedback(EiInfo inInfo) {
		EiInfo out=new EiInfo(); 
		ZMCGContactReceive _dom = new ZMCGContactReceive();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			
			String fdContactListId = _dom.getFdContactlistId();
			String fdReceiveId = _dom.getFdReceiveId();//接收部门
			String fdSendDepartId = _dom.getFdSendDepartId();//发送部门
			String fdTitle = _dom.getFdTitle();
			String fdSendTime = _dom.getFdSendTime();
			String fdContent = _dom.getFdContent();
			
			_dom.setFdFeedbackTim(StaticTools.getDateTime());
			_dom.setFdFeedbackPer(UserSession.getInSessionProperty("UserCname").toString());
			_dom.setFdFeedbackCon(_dom.getFdFeedbackCon());
			_dom.setFdContactlistId(fdContactListId);
			_dom.setFdTitle(fdTitle);
			_dom.setFdReceiveId(fdReceiveId);
			_dom.setFdSendDepartId(fdSendDepartId);
			_dom.setFdSendTime(fdSendTime);
			_dom.setFdContent(fdContent);
			_dom.setFdMiningId(UserSession.getInSessionProperty("miningCode").toString());	//矿井id
		    this.dao.update("ZMCGContactReceive.update", _dom);
//			String fdFeedbackPerson = (String) UserSession.getInSessionProperty("UserCname");//反馈人
//			String fdFeedbackPersonId = UserSession.getUserId() == null ? "" : UserSession.getUserId().toString();//反馈人ID
//			String fdFeedbackTime = StaticTools.getDateTime();//反馈时间
//			String fdContactListId = _dom.getFdContactlistId();
//			String fdFeedbackDepartId = UserSession.getInSessionProperty("orgCode") == null ? "" : UserSession.getInSessionProperty("orgCode").toString();//发送部门
			
//			String fdReceiveId = UserSession.getInSessionProperty("orgCode") == null ? "" : UserSession.getInSessionProperty("orgCode").toString();//接收部门
//			this.dao.update( "ZMCGContactReceive.modifyFeedbackOk",_dom);
		    
//		    ZMCGContactListFeedBack bean = new ZMCGContactListFeedBack();
//		    bean.setFdContactListId(fdContactListId);
//		    bean.setFdContent(_dom.getFdFeedbackContent());
//		    bean.setFdSendDepartId(fdFeedbackDepartId);
//
//		    bean.setFdSendPerson(fdFeedbackPerson);
//		    bean.setFdSendPersonId(fdFeedbackPersonId);
//		    bean.setFdSendTime(fdFeedbackTime);
//		    bean.setFdModifyFlag("0");
//		    bean.setFdKeyId(TablePk.getInstance().getNextValue("T_CG_CONTACTLISTFEEDBACK"));
//		    this.dao.insert("ZMCGContactListFeedBack.insert", bean);//主表状态
		    
//		    String fdFeedbackCon = bean.getFdContent();
//		    String fdFeedbackPer = bean.getFdSendPerson();
//		    String fdFeedbackTim = bean.getFdSendTime();
//		    
//		    _dom.setFdFeedbackCon(fdFeedbackCon);
//		    _dom.setFdFeedbackPer(fdFeedbackPer);
//		    _dom.setFdFeedbackTim(fdFeedbackTim); 
		    
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out; 
	}
}
		    
		    
		    
//		String fdSendDepartId = UserSession.getInSessionProperty("orgCode") == null ? "" : UserSession.getInSessionProperty("orgCode").toString();//反馈部门
//		String fdSendDepart = Department.getInstance().getDepartmentNameById(fdSendDepartId);
//		String fdFeedbackPerson = UserSession.getUserId() == null ? "" : UserSession.getUserId().toString();//反馈人ID
//		String fdFeedbackPerson = (String) UserSession.getInSessionProperty("UserCname");//反馈人
//		String fdFeedbackTime = StaticTools.getDateTime();//反馈时间
//		String fdContactListId = inInfo.getBlock("result").getCellStr(0, "fdContactlistId");
		
//		EiInfo outInfo = super.update(inInfo, "ZMCGContactReceive.modifyFeedbackOk");//更新联系单状态
//		
//		inInfo.addBlock("resultDetails").addBlockMeta(new ZMCGContactListFeedBack().eiMetadata);
//		
//		inInfo.getBlock("resultDetails").setCell(0, "fdKeyId", TablePk.getInstance().getNextValue("T_CG_CONTACTLISTFEEDBACK"));
//		inInfo.getBlock("resultDetails").setCell(0, "fdContactListId", fdContactListId);
//		inInfo.getBlock("resultDetails").setCell(0, "fdSendDepartId", fdSendDepartId);
//		inInfo.getBlock("resultDetails").setCell(0, "fdSendDepart", fdSendDepart);
//		inInfo.getBlock("resultDetails").setCell(0, "fdSendPersonId", fdSendPersonId);
//		inInfo.getBlock("resultDetails").setCell(0, "fdSendPerson", fdSendPerson);
//		inInfo.getBlock("resultDetails").setCell(0, "fdContent", inInfo.getBlock("result").getCellStr(0, "fdFeedbackContent"));
//		inInfo.getBlock("resultDetails").setCell(0, "fdSendTime", fdSendTime);
//		inInfo.getBlock("resultDetails").setCell(0, "fdModifyFlag", "0");
//		
//		outInfo = super.insert(inInfo, "ZMCGContactListFeedBack.insert", "resultDetails");//主表状态
//		return outInfo;
//	}
//}
